package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/14 21:32
 **/
public class Offer20 {
    class Solution {
        public boolean isNumber(String s) {
            s = s.trim();
            char[] arr = s.toCharArray();
            boolean isNum = false, isFloat = false, isE = false;
            for(int i = 0; i < arr.length; ++i){
                char c = arr[i];
                if((c == '+' || c == '-') &&
                        ((i == 0) || ((i > 0) && (arr[i-1] == 'e' || arr[i-1] == 'E')))){
                }else if((c == 'e' || c == 'E') && !isE && isNum){
                    isNum = false;
                    isE = true;
                }else if(c == '.' && !isFloat && !isE){
                    isFloat = true;
                }else if(Character.isDigit(c)){
                    isNum = true;
                }else {
                    return false;
                }
            }
            return isNum;
        }
    }

}